package cece.service.impl;


import cece.entity.Music;
import cece.entity.MusicResp;
import cece.mapper.MusicMapper;
import cece.mapper.MusicResponsetory;
import cece.service.MusicService;
import org.springframework.beans.factory.annotation.Autowired;
;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2020/5/23.
 */
@Service
public class MusicServiceImpl implements MusicService {
    @Autowired
    MusicResponsetory musicResponsetory;

    @Autowired
    MusicMapper musicMapper;
    @Override
    public MusicResp findAll(Integer pageSie, Integer pageNum) {

        //声明pageAble
        PageRequest pageRequest = new PageRequest(pageNum-1, pageSie);
        //jpa分页
        Page<Music> all = (Page<Music>) musicResponsetory.findAll(pageRequest);
        //获取到展示的数据信息
        List<Music> content=all.getContent();
        //或渠道总数
        long totalElements = all.getTotalElements();

        MusicResp musicResp = new MusicResp();

        musicResp.setTotal(totalElements);
        musicResp.setMusicList(content);
        return musicResp;
    }

    @Override
    public List<Music> findMusics(String zname) {
        List<Music> musics = musicMapper.findMusics(zname);
        return musics;
    }

    @Override
    public Music findByYid(Integer yid) {

        return musicMapper.findByYid(yid);
    }


}
